<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>购买代金券</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div>
  代金券名称：{$coupon.name}<br/>
  代金券优惠：￥{$coupon.reduce}<br/>
  优惠券名称：{$coupon.name}<br/>
</div>
<div>
  <div>
    <input type="radio" name="pay_type" value="1">支付宝
    <input type="radio" name="pay_type" value="2">微信
    <input type="radio" name="pay_type" value="3">余额
    <input type="hidden" name="cash_coupon_id" value="{$coupon.id}">
  </div>
  <div>
    <button onclick="buy()">提交</button>
  </div>
</div>
</body>
</html>
<script>
  function buy(){
      var pay_type = $('input[name=pay_type]:checked').val();
      var id = $('input[name=cash_coupon_id]').val();
      if(pay_type == ''){
          alert('请选择支付方式');
          return false;
      }
      if(pay_type == 1){
          window.location.href = "{:url('Alipay/buy_cash_coupon')}?id="+id+"&pay_type="+pay_type;
      }else if(pay_type == 2){
          window.location.href = "{:url('Weixinpay/buy_cash_coupon')}?id="+id+"&pay_type="+pay_type;
      }else{
          $.post("{:url('Index/buy_cash_coupon')}",
              {id:id,pay_type:pay_type},
              function(data){
                if(data.code == 1){
                    alert('支付成功');
                }else{
                    alert(data.msg);
                }
              }
          );
      }
  }
</script>